package com.example.simplesvc.coordination;


import com.example.simplesvc.concurrent.lock.DBLock;
import com.example.simplesvc.concurrent.lock.DBLockFactory;
import com.example.simplesvc.entity.Node;
import com.example.simplesvc.mappers.NodeMapper;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.lang.reflect.Executable;

@Component
public class Coordinator implements InitializingBean {


    @Autowired
    NodeMapper mapper;
    @Autowired
    DBLockFactory factory;
    public void election() {
        //竞选 leader，竞选上就是leader 选不上就是worker


        factory.getLock("leader_election")
                .executeWithLock(() -> {

//                    Node node = new Node();
//                    node.setName();
//                    mapper.queryActiveLeader()
                    return null;
                });





    }

    @Override
    public void afterPropertiesSet()  {
            election();
    }
}
